#pragma once

#include "Chartconfig.h"
#include "Chartdata.h"
#include "resource.h"

#include <math.h>

#define CHARTS_MAX 10


// CChartControl

class CChartControl : public CWnd
{
	DECLARE_DYNAMIC(CChartControl)

public:
	CChartControl();
	virtual ~CChartControl();

protected:
	DECLARE_MESSAGE_MAP()

public:
	Chartconfig m_cChartConfig;
	CChartdata m_ChartData[CHARTS_MAX];

	HBITMAP m_hMemBitmap;
	HDC m_hMemDC;

	CRect rcWindow;
	CRect rcData;
	CRect rcRangebtn, rcAutoscalebtn;	
	HFONT hFont, hOldFont;
	double dblXIntv, dblYIntv;
	int nXDataSize;
	double dblYDataSize, dblYCenter, dblYMin, dblYMax, dblYPixelSize, dblYDataPerP;

	int m_nScaleY;
	bool m_bPlusClick,m_bMinusClick;
	bool m_bWarningMove;
	bool m_bAutoscaleCheck;

	CBitmapButton m_cbtnRange, m_cbtnAutoscale;
	//CYRangeSetDlg m_YRangdlg;

public:
	void DrawChart(HDC hDC);
	void CalcDataRect();
	void CalcAxis();
	void DrawBG(HDC hDC);
	void DrawAxisLine(HDC hDC);
	void DrawAxisX(HDC hDC);
	void DrawAxisY(HDC hDC);
	void DrawData(HDC hDC);
	void DrawDotRect(HDC hDC,int x, int y, int nW, int nH);
	void DrawButton();

	void DrawWarning(HDC hDC);
	//BOOL m_bWaringLine[X_SCALE];
	void GraphExpend();
	void GraphReduce();
	struct WarningBar{
		BOOL POS;
		int LEVEL;
	} m_WarningLine[X_SCALE];

	void SetWarning();
	void SetWarning(int level);	
	void Clear();
	void CreateMemResource();

	afx_msg void OnPaint();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	afx_msg void OnBtnClicked(UINT);

};


